package com.jxaummd.aquaculture.ui.fragment.first.fun;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.blankj.utilcode.util.ToastUtils;
import com.jxaummd.aquaculture.R;
import com.jxaummd.aquaculture.base.BaseBackFragment;
import com.jxaummd.aquaculture.entity.Device;
import com.jxaummd.aquaculture.util.net.RestClient;
import com.jxaummd.aquaculture.util.net.callback.ISuccess;


public class ChangePasswordFragment extends BaseBackFragment {
    private Device device;
    private EditText mEditPassword = null;
    private EditText mEditNewPassword = null;
    private Button mBtnSubmit = null;

    public static ChangePasswordFragment newInstance(Device device) {
        Bundle args = new Bundle();
        ChangePasswordFragment fragment = new ChangePasswordFragment();
        fragment.device = device;
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_device_change_password, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        Toolbar toolbar = view.findViewById(R.id.toolbar);
        mEditPassword = view.findViewById(R.id.fragment_device_change_password_password);
        mEditNewPassword = view.findViewById(R.id.fragment_device_change_password_newPassword);
        mBtnSubmit = view.findViewById(R.id.fragment_device_change_password_submit);
        toolbar.setTitle("修改密码");
        initToolbarNav(toolbar);


        mBtnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String password  = mEditNewPassword.getText().toString().trim();
                RestClient.builder()
                        .url("http://jxaummd.com:8081/lock/changePwd.do")
                        .params("id",1)
                        .params("password",password)
                        .success(new ISuccess() {
                            @Override
                            public void onSuccess(String response) {
                                if(response!=null){
                                    ToastUtils.showShort("密码修改成功！");
                                    pop();
                                }
                            }
                        })
                        .build()
                        .get();

            }
        });

    }

}
